#ifndef TRANSFORMERCONTENTTARGETREACHABLE_HPP_3

#include "logger.hpp"
#include "transContentDefine.h"
#include "transContentErrorCode.h"
#include "transContentAssistent.hpp"
#include "transContentIDispatcherResponse.hpp"
#include "transContentIRemove.hpp"
#include "transContentThreadPool.hpp"

class TransContentFuncCallTargetReachable: public transContentIDispResponse, public transContentIRemove{
private:
	int timeout;
	int localPort;
	NodeAddr target;
	targetReachAbleCallback tracb;
	int result;
	int canBeRemoved;
	pthread_cond_t waitCond;
	pthread_mutex_t waitMutex;

public:
	TransContentFuncCallTargetReachable():timeout(INT_MAX), localPort(0), tracb(NULL), result(0), canBeRemoved(0), waitCond(PTHREAD_COND_INITIALIZER), waitMutex(PTHREAD_MUTEX_INITIALIZER){debug_enter();}

	virtual ~TransContentFuncCallTargetReachable(){
		debug_enter();

		debug_leave();
	}

	int getTimeout() const {
		return this->timeout;
	}

	int canRemoved() const {
		return this->canBeRemoved;
	}

	void setTimeout(int timeout){
		this->timeout = timeout;
	}
	
	int getLocalPort() const {
		return this->localPort;
	}
	void setLocalPort(int port){
		this->localPort = port;
	}
	
	void setTarget(const NodeAddr* target){
		this->target.serial_id = target->serial_id;
	}

	NodeAddr getTarget(){
		return this->target;
	}
	
	void setFinishCallback(targetReachAbleCallback tracb){
		this->tracb = tracb;
	}

	targetReachAbleCallback getFinshedCallback() const {
		return this->tracb;
	}
	
	int canRemoved(){
		return canBeRemoved;
	}

	int targetReachable();

	int response(char* content, int index);
private:
	static void* finishedRoute(void* p);

	void finishIns();

	void reachableFinish();
};
